<!DOCTYPE html>
<html>
<head>
<title></title>
<#include "/header.html">
</head>
<body>
	<div id="rrapp" v-cloak>
		<div v-show="showList">
			<div class="grid-btn">

				<!-- <div class="form-group col-sm-2">
                <input type="text" class="form-control" v-model="q.key" @keyup.enter="query" placeholder="输入查询条件">
            </div> -->
				<input type="file" name="file" multiple="multiple" id="excelFile"/><br>
				<a class="btn btn-primary" onclick="UpladFile()">导入</a> <!-- <a class="btn btn-primary"
					@click="query">查询</a>

				<#if shiro.hasPermission("booktagmapping:save")> <a
					class="btn btn-primary" @click="add"><i class="fa fa-plus"></i>&nbsp;新增</a>
				</#if>
				<#if shiro.hasPermission("booktagmapping:update")> <a
					class="btn btn-primary" @click="update"><i
					class="fa fa-pencil-square-o"></i>&nbsp;修改</a> </#if>
				<#if shiro.hasPermission("booktagmapping:delete")> <a
					class="btn btn-primary" @click="del"><i class="fa fa-trash-o"></i>&nbsp;删除</a>
				</#if> -->
				<a class="btn btn-primary" onclick="downLoadFile()">导出</a>
				<!-- <input type="button" id="down" onclick="downLoadFile()"> -->
			</div>
			<table id="jqGrid"></table>
			<div id="jqGridPager"></div>
		</div>

		<div v-show="!showList" class="panel panel-default">
			<div class="panel-heading">{{title}}</div>
			<form class="form-horizontal">
				<div class="form-group">
					<div class="col-sm-2 control-label">标签编号</div>
					<div class="col-sm-10">
						<input type="text" class="form-control"
							v-model="bookTagMapping.tagCode" placeholder="标签编号" />
					</div>
				</div>
				<div class="form-group">
					<div class="col-sm-2 control-label">标签名称</div>
					<div class="col-sm-10">
						<input type="text" class="form-control"
							v-model="bookTagMapping.tagName" placeholder="标签名称" />
					</div>
				</div>
				<div class="form-group">
					<div class="col-sm-2 control-label"></div>
					<input type="button" class="btn btn-primary" @click="saveOrUpdate"
						value="确定" /> &nbsp;&nbsp;<input type="button"
						class="btn btn-warning" @click="reload" value="返回" />
				</div>
			</form>
		</div>
	</div>

	<script
		src="${request.contextPath}/statics/js/modules/book/book-info-import.js?_${.now?long}"></script>
</body>
<script type="text/javascript">
	var xhr;
	var index;
	var date_token;
	//上传文件方法
	function UpladFile() {
	    var fileObj = document.getElementById("excelFile").files[0]; // js 获取文件对象
	    var url = "http://47.100.117.234:9393/wdb-security-zs/upDown/file/upexecel"; // 接收上传文件的后台地址 
	    
	    var form = new FormData(); // FormData 对象
	    form.append("file", fileObj); // 文件对象
	    
	    xhr = new XMLHttpRequest();  // XMLHttpRequest 对象
	    xhr.open("post", url, true); //post方式，url为服务器请求地址，true 该参数规定请求是否异步处理。
	    xhr.onload = uploadComplete; //请求完成
	    xhr.onerror =  uploadFailed; //请求失败
	    xhr.send(form); //开始上传，发送form数据
	    index = layer.load(1, {
	    	  shade: [0.2,'#fff'] //0.1透明度的白色背景
	    	});
	}
	
	//上传成功响应
	function uploadComplete(evt) {
	 //服务端接收完文件返回的结果
	     var data = JSON.parse(evt.target.responseText);
	 	 layer.close(index);
	     if(data.detail.code==100) {
	    	 console.log(data.detail.message);
	    	 date_token = data.detail.message;
	         layer.msg("解析成功！");
	         vm.reload(date_token);
	     }else{
	    	 layer.msg(data.detail.message);
	     }
	}
	//上传失败
	function uploadFailed(evt) {
		layer.msg("上传失败！");
	}
	  //取消上传
	function cancleUploadFile(){
	    xhr.abort();
	}
	function downLoadFile(){
		var urlFile="http://127.0.0.1:9001/wdb-security/upDown/file/export?currentTime="+date_token;
        var elemIF = document.createElement("iframe");     
        elemIF.src = urlFile;     
        elemIF.style.display = "none";     
        document.body.appendChild(elemIF);  
		//this.location.href="http://127.0.0.1:9001/wdb-security/upDown/file/export?curretnTime="+"2018-01-26 11:56:33"
	}
</script>
</html>